package com.sec.etech.sys.util;

import org.openbpm.base.core.util.StringUtil;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestHolder {

    public static HttpServletRequest getRequest() {
        HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return req;
    }

    public static HttpServletResponse getResponse() {
        HttpServletResponse resp = ((ServletWebRequest) RequestContextHolder.getRequestAttributes()).getResponse();
        return resp;
    }

    //获取url
    public static String getUrl() {
        String url = ContextUtil.getWebUrlPrefix();
        if (StringUtil.isEmpty(url)) {
            HttpServletRequest requet = getRequest();
            url = requet.getScheme() + "://" + requet.getServerName() + ":" + requet.getServerPort();
        }

        if ("http://10.8.1.81".equals(url) || "http://10.8.1.81/".equals(url)){
            System.out.println("原域名：["+url+"]");
            url = "http://etech.stcetech.ad01.sec.com";
        }

        return url;
    }
}
